package com.ops.uitl.tapestry;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;
import com.ops.uitl.common.Common;
import com.ops.uitl.data.IData;

public class BaseContext implements Serializable {

	private String staffId;
	private String staffName;
	private String staffType;
	private String deptId;
	private String deptName;
	private String deptCode;
	private String cityId;
	private String cityName;
	private String epachyId;
	private String epachyName;
	private String loginEpachyId;
	private String tradeEpachyId;
	private String jobCode;
	private String roles;
	
	private String loginType;
	private String agentMainPhone;
	private String serialNumber;
	private String password;
	
	private static String productMode;
	private static String provinceId;
	private static String subSysCode;
	private static String version;
	private static String style;
	private static String releaseNo;
	private static String contextName;
	
	transient private boolean validate;
	
	private Map privMap = new HashMap();
	private Map attrMap = new HashMap();
	private IData expandData;
	
	private String userId;
	private String userEparchyCode;
	private String netTypeCode;
	
	static{
		try {
			productMode = Common.getInstance().getProperty("project/productmode");
			provinceId = Common.getInstance().getProperty("project/province");
			subSysCode = Common.getInstance().getProperty("project/name");
			version = Common.getInstance().getProperty("project/version");
			style = Common.getInstance().getProperty("project/style");
			//releaseNo = Common.getInstance().getPropertyByProp("RELEASE_NO");
			releaseNo = Common.getInstance().getProperty("project/RELEASE_NO");
			contextName = Common.getInstance().getProperty("project/contextname");
		} catch (Exception e) {
			System.out.println("get globar parameter [productMode|provinceId|subSysCode|style|releaseNo|contextName] error");
		}
	}
	
	public String getStaffId() {
		return staffId;
	}
	public void setStaffId(String staffId) {
		this.staffId = staffId;
	}
	
	public String getStaffName() {
		return staffName;
	}
	public void setStaffName(String staffName) {
		this.staffName = staffName;
	}
	
	public String getStaffType() {
		return staffType;
	}
	public void setStaffType(String staffType) {
		this.staffType = staffType;
	}

	public String getDeptId() {
		return deptId;
	}
	public void setDeptId(String deptId) {
		this.deptId = deptId;
	}
	
	public String getDeptCode() {
		return deptCode;
	}
	public void setDeptCode(String deptCode) {
		this.deptCode = deptCode;
	}
	
	public String getDeptName() {
		return deptName;
	}
	public void setDeptName(String deptName) {
		this.deptName = deptName;
	}
	
	public String getCityId() {
		return cityId;
	}
	public void setCityId(String cityId) {
		this.cityId = cityId;
	}
	
	public String getCityName() {
		return cityName;
	}
	public void setCityName(String cityName) {
		this.cityName = cityName;
	}
	
	public String getEpachyId() {
		return epachyId;
	}
	public void setEpachyId(String epachyId) {
		this.epachyId = epachyId;
	}
	
	public String getEpachyName() {
		return epachyName;
	}
	public void setEpachyName(String epachyName) {
		this.epachyName = epachyName;
	}
	
	public String getLoginEpachyId() {
		return loginEpachyId;
	}
	public void setLoginEpachyId(String loginEpachyId) {
		this.loginEpachyId = loginEpachyId;
	}
	
	public String getTradeEpachyId() {
		return tradeEpachyId == null ? loginEpachyId : tradeEpachyId;
	}
	public void setTradeEpachyId(String tradeEpachyId) {
		this.tradeEpachyId = tradeEpachyId;
	}
	
	public String getRoles() {
		return roles;
	}
	public void setRoles(String roles) {
		this.roles = roles;
	}
	
	public String getJobCode() {
		return jobCode;
	}
	public void setJobCode(String jobCode) {
		this.jobCode = jobCode;
	}
	
	public void setSerialNumber(String serialNumber) {
		this.serialNumber = serialNumber;
	}	
	public String getSerialNumber() {
		return this.serialNumber;
	}
	
	public String getPassword() {
		return password;
	}
	public void setPassword(String password) {
		this.password = password;
	}
	
	public String setProductMode() {
		return productMode;
	}
	public void getProductMode(String productMode) {
		this.productMode = productMode;
	}

	public String getVersion() {
		return version;
	}
	public void setVersion(String version) {
		this.version = version;
	}
	
	public String getProvinceId() {
		return provinceId;
	}
	public void setProvinceId(String provinceId) {
		this.provinceId = provinceId;
	}
	
	public String getSubSysCode() {
		return subSysCode;
	}
	public void setSubSysCode(String subSysCode) {
		this.subSysCode = subSysCode;
	}
	
	public String getStyle() {
		return style;
	}
	public void setStyle(String style) {
		this.style = style;
	}
	
	public String getReleaseNo() {
		return releaseNo;
	}
	public void setReleaseNo(String releaseNo) {
		this.releaseNo = releaseNo;
	}
	
	public String getContextName() {
		return contextName;
	}
	public void setContextName(String contextName) {
		this.contextName = contextName;
	}
	
	public boolean isValidate() {
		return validate;
	}
	public void setValidate(boolean validate) {
		this.validate = validate;
	}
	
	public Map getPrivMap() {
		return privMap;
	}
	public void setPrivMap(Map privMap) {
		this.privMap = privMap;
	}
	
	public IData getExpandData() {
		return expandData;
	}
	public void setExpandData(IData expandData) {
		this.expandData = expandData;
	}
	
	public boolean hasPriv(String privCode) {
		if ("SUPERUSR".equals(staffId)) return true;
		return privMap.keySet().contains(privCode);
	}

	public boolean isProv(String provinceId) {
		return provinceId.equals(this.provinceId);
	}
	
	public boolean isProductMode() {
		return productMode != null && "true".equals(productMode);
	}
	
	public void setUserId(String userId) {
		this.userId = userId;
	}
	public String getUserId() {
		return this.userId;
	}
	
	public void setUserEparchyCode(String userEparchyCode) {
		this.userEparchyCode = userEparchyCode;
	}
	public String getUserEparchyCode() {
		return this.userEparchyCode;
	}
	
	public void setNetTypeCode(String netTypeCode) {
		this.netTypeCode = netTypeCode;
	}
	public String getNetTypeCode() {
		return this.netTypeCode;
	}
	
	public Object getAttribute(String attribute) {
		return attrMap.get(attribute);
	}
	public void setAttribute(String attribute, Object value) {
		attrMap.put(attribute, value);
	}
	public void removeAttribute(String attribute) {
		attrMap.remove(attribute);
	}
	public String[] getAttributeNames() {
		return (String[]) attrMap.keySet().toArray(new String[0]);
	}
	public String getLoginType() {
		return loginType;
	}
	public void setLoginType(String loginType) {
		this.loginType = loginType;
	}
	public String getAgentMainPhone() {
		return agentMainPhone;
	}
	public void setAgentMainPhone(String agentMainPhone) {
		this.agentMainPhone = agentMainPhone;
	}
	
	public String toString() {
		String loginType = getLoginType();
		String staffId = getStaffId();
		String staffName = getStaffName();
		String deptId = getDeptId();
		String deptCode = getDeptCode();
		String deptName = getDeptName();
		String cityId = getCityId();
		String cityName = getCityName();
		String epachyId = getEpachyId();
		String loginEpachyId = getLoginEpachyId();
		String version = getVersion();
		String provinceId = getProvinceId();
		String subSysCode = getSubSysCode();
		boolean productMode = isProductMode();
		String serialNumber = getSerialNumber();
		String agentMainPhone = getAgentMainPhone();
		
		StringBuffer str = new StringBuffer();
		str.append("productMode='" + productMode + "' ");
		if (loginType != null) str.append("loginType='" + loginType + "' ");
		if (staffId != null) str.append("staffId='" + staffId + "' ");
		if (staffName != null) str.append("staffName='" + staffName + "' ");
		if (staffType != null) str.append("staffType='" + staffType + "' ");
		if (deptId != null) str.append("deptId='" + deptId + "' ");
		if (deptCode != null) str.append("deptCode='" + deptCode + "' ");
		if (deptName != null) str.append("deptName='" + deptName + "' ");
		if (cityId != null) str.append("cityId='" + cityId + "' ");
		if (cityName != null) str.append("cityName='" + cityName + "' ");
		if (epachyId != null) str.append("epachyId='" + epachyId + "' ");
		if (epachyName != null) str.append("epachyName='" + epachyName + "' ");
		if (loginEpachyId != null) str.append("loginEpachyId='" + loginEpachyId + "' ");
		if (roles != null) str.append("roles='" + roles + "' ");
		if (version != null) str.append("version='" + version + "' ");
		if (provinceId != null) str.append("provinceId='" + provinceId + "' ");
		if (subSysCode != null) str.append("subSysCode='" + subSysCode + "' ");
		if (contextName != null) str.append("contextName='" + contextName + "' ");
		if (releaseNo != null) str.append("releaseNo='" + releaseNo + "' ");
		if (serialNumber != null) str.append("serialNumber='" + serialNumber + "' ");
		if (agentMainPhone != null) str.append("agentMainPhone='" + agentMainPhone + "' ");
		return str.toString();
	}
	
}